package com.leyou.goodsweb.controller;

import com.leyou.goodsweb.service.GoodsHtmlService;
import com.leyou.goodsweb.service.GoodsWebService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.Map;

@Controller
public class GoodsWebController {

    @Autowired
    private GoodsHtmlService goodsHtmlService;

    @Autowired
    private GoodsWebService goodsWebService;

    @GetMapping("/item/{id}.html")
    public String toItemPage(@PathVariable Long id, Model model){

        Map<String, Object> map = goodsWebService.loadData(id);
        model.addAllAttributes(map);
        goodsHtmlService.createHtml(id);
        return "item";
    }
}
